package co.angluzha.business.student.controller;

import co.angluzha.business.clasx.feign.ClasxControllerFeign;
import co.angluzha.business.student.service.StudentService;
import co.angluzha.commons.base.result.R;
import co.angluzha.commons.base.result.Rt;
import co.angluzha.commons.redis.utils.RedisLock;
import co.angluzha.data.student.entity.Student;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * oc.angluzha.business.student.controller文档说明
 *
 * @author Angluzha
 * @version 2022/11/21
 */
@RestController
@RequestMapping("/stu")
public class StudentController {

    @Resource
    private StudentService studentService;

    @RequestMapping("/{num}")
    public R hello(@PathVariable Integer num){
        int x = 10/num;
        return Rt.success("创建ok");
    }

    @PostMapping("/")
    public R insert(@Validated Student student){
        studentService.save(student);
        return Rt.success();
    }
    @PutMapping("/")
    public R update(@Validated(Student.Update.class) Student student){
        studentService.updateById(student);
        return Rt.success();
    }

    @RequestMapping("/list")
    public R getList(){
        List<Student> stuList = studentService.list();
        return Rt.success(stuList);
    }
    @GetMapping("/{id}")
    public R getById(@PathVariable Integer id){

        Student byId = studentService.getById(id);
        return Rt.success(byId);
    }
}
